package com.mstarc.app.mnfc.mstarcApiUtils;

import android.util.Log;

import mstarc_os_api.mstarc_os_api_msg;

/**
 * @author 崔健伟
 * @version V1.0
 * @Title: SwitchModeUtil.java
 * @Package com.mstarc.app.mnfc.mstarcApiUtils
 * @Description:
 * @date 2017/6/21 10:59
 */
public class SwitchModeUtil {
    private static final String TAG = "SwitchModeUtil";
    //    private static final String PARAM1 = "44 42 ff ff 08 0d 06 9e e9 3d 98 18 fe";
    private static final int[] PARAM1 = new int[]{0x44, 0x42, 0xff, 0xff, 0x08, 0x0d, 0x06, 0x9e, 0xe9, 0x3d, 0x98, 0x18, 0xfe};
    //    private static final String PARAM2 = "44 42 02 00 01 00";
    private static final int[] PARAM2 = new int[]{0x44, 0x42, 0x02, 0x00, 0x01, 0x00};

    public static int[] switchMode(mstarc_os_api_msg m_api_msg) {
        int[] ints1 = getReset(m_api_msg);
        int[] ints2 = getApdu(m_api_msg, PARAM1);
        int[] ints3 = getReset(m_api_msg);
        int[] ints4 = getApdu(m_api_msg, PARAM1);
        int[] ints5 = getApdu(m_api_msg, PARAM2);
//        logIntArray(ints1, "reset1:");
//        logIntArray(ints2, "reset2:");
//        logIntArray(ints3, "reset3:");
//        logIntArray(ints4, "reset4:");
//        logIntArray(ints5, "reset5:");
        return ints5;
    }

    private static int[] getReset(mstarc_os_api_msg m_api_msg) {
        return MstarcResetUtil.reset(m_api_msg);
    }

    private static int[] getApdu(mstarc_os_api_msg m_api_msg, int[] params) {
        return ApduUtil.apdu(m_api_msg, params);
    }

    private static void logIntArray(int[] intArray, String tagTitle) {
        String str = "";
        if (intArray != null && intArray.length >= 0) {
            for (int i : intArray) {
                str += i + ",";
            }
        }
//        startLog(tagTitle, str);
        startLog(tagTitle, BytetohexStringUtil.BytetohexString(intArray));
    }

    private static void startLog(String logTitle, String logContent) {
        Log.d(TAG, logTitle + logContent);
    }
}
